﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Program15
{
    public partial class Form1 : Form
    {

        private int playerNum = 0;
        private int computerNum = 0;
        private Player _player;
        private Computer _computer;
        public Form1()
        {
            InitializeComponent();
            _player = new Player();
            _computer = new Computer();
        }

        private void btnRock_Click(object sender, EventArgs e)
        {
            //石头
            var fistStr = btnRock.Text;
            GameLogic(fistStr);
        }

        private void btnScissor_Click(object sender, EventArgs e)
        {
            //剪刀
            var fistStr = btnScissor.Text;
            GameLogic(fistStr);
        }

        private void btnPaper_Click(object sender, EventArgs e)
        {
            //布
            var fistStr = btnPaper.Text;
            GameLogic(fistStr);
        }

        /// <summary>
        /// 游戏逻辑
        /// </summary>
        /// <param name="fistStr"></param>
        private void GameLogic(string fistStr)
        {
            //玩家出拳
            lblbPlayer.Text = fistStr;
            var enumPlayer = _player.ShowFist(fistStr);

            //电脑出拳
            var enumComputer = _computer.ShowFist();
            lblComputer.Text = enumComputer.ToString();

            //裁判判定
            var eFist = Judge.GetResult((int)enumPlayer, (int)enumComputer);
            lblResult.Text = eFist.ToString();
            if (eFist.ToString() == "玩家赢")
            {
                playerNum++;
            }
            else if(eFist.ToString()=="电脑赢")
            {
                computerNum++;
            }
            lblPlayerNum.Text = playerNum.ToString();
            lblComputerNum.Text = computerNum.ToString();
        }
    }
}
